package com.example.rizhaoscienceandtechnologymuseum.Utils;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.example.baselibrary.Base.BaseCustomer;
import com.example.baselibrary.Utils.SPUtils;
import com.example.baselibrary.Utils.SelfToastUtil;
import com.example.baselibrary.Utils.StringUtil;
import com.example.rizhaoscienceandtechnologymuseum.R;

public class BottomSettingDialog extends BottomDialogBase {

    private Context context;
    private EditText url;
    private EditText gateNo;
    private EditText faceValue;
    private Button btComfig;
    private static SettingConfig setting;

    public BottomSettingDialog(final Context context) {
        super(context);
        this.context = context;

        url.setText((String)SPUtils.get(context, BaseCustomer.BASE_URL, ""));
        gateNo.setText((String)SPUtils.get(context, BaseCustomer.CHECK_GATENO, ""));
        faceValue.setText((String)SPUtils.get(context, BaseCustomer.FACEVALUE, ""));

        btComfig.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (StringUtil.isNullOrEmpty(url.getText().toString())) {
                    SelfToastUtil.getInstance().show("请输入基础地址");
                    return;
                }
                if (StringUtil.isNullOrEmpty(gateNo.getText().toString())) {
                    SelfToastUtil.getInstance().show("请输入终端编号");
                    return;
                }
                if (StringUtil.isNullOrEmpty(faceValue.getText().toString())) {
                    SelfToastUtil.getInstance().show("请输入人脸阈值");
                    return;
                }

                SPUtils.put(context, BaseCustomer.BASE_URL, url.getText().toString());
                SPUtils.put(context, BaseCustomer.CHECK_GATENO, gateNo.getText().toString());
                SPUtils.put(context, BaseCustomer.FACEVALUE, faceValue.getText().toString());
                setting.settingCon();
                dismiss();
            }
        });
    }

    @Override
    protected void onCreate() {

        setContentView(R.layout.widget_setting_dialog);
        url = findViewById(R.id.et_setting_url);
        gateNo = findViewById(R.id.et_setting_gateno);
        faceValue = findViewById(R.id.et_setting_face_value);
        btComfig = findViewById(R.id.bt_setting_comfig);

    }

    public interface SettingConfig{
        void settingCon();
    }

    public static void SettingConfigListener(SettingConfig settingConfig){
        setting = settingConfig;
    }
}
